//
// Created by 86176 on 2021/11/3.
//

#include "Session.h"

Session::Session() {
    recvBuffer = new IoBuffer();
    sendBuffer = new IoBuffer();
    //packetLen = 0;
    //socket = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
    //Olp.hEvent = WSACreateEvent();
    //lpFlags = 0;
    //nReadSequence = nCurrentReadSequence;
}

Session::Session(int _fd) {
    fd = _fd;
//    time_t now_time = time(NULL);

    // 获取当前时间点
    auto now = std::chrono::system_clock::now();

    // 转换为时间戳
    auto duration = now.time_since_epoch();

    // 将时间戳转换为毫秒
    auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();

    // 输出时间戳
    std::cout << "Current UNIX timestamp (milliseconds): " << millis << std::endl;

    idleStatus = new IdleStatus(millis);
    recvBuffer = new IoBuffer();
    sendBuffer = new IoBuffer();
}

Session::~Session() {
    //    closesocket(socket);
    delete(recvBuffer);
    delete(sendBuffer);;
    delete(idleStatus);;
    //    if(NULL != idleStatus)
    //        delete(idleStatus);
    //    printf("session destroy.\n");
}

IoBuffer *Session::getRecvBuffer() const {
    return recvBuffer;
}
IoBuffer *Session::getSendBuffer() const {
    return sendBuffer;
}

